import React from 'react';
import {
    Form,
    Input,
    Button,
    NavBar,
    Toast
} from 'antd-mobile'
import {useNavigate} from "react-router-dom"
import { postUrl } from "../../utils/request"
const Index = () => {
    const navigate=useNavigate()
    const onFinish = async (values) => {
        const res = await postUrl('/loginUp', values)
        console.log(res)
        const { code, mes } = res.data
        if (code === 200) {
            Toast.show({
                icon: 'success',
                content: mes,
            })
            navigate('/home')
        } else {
            Toast.show({
                icon: 'fail',
                content: mes,
            })
        }
    };
    return (
        <div>
            <NavBar>登录</NavBar>
            <Form
                onFinish={onFinish}
                layout='horizontal'
                footer={
                    <Button block type='submit' color='primary'>
                        提交
                    </Button>
                }
            >
                <Form.Item
                    name='username'
                    label='账号'
                    rules={[{ required: true, message: '姓名不能为空' }]}
                >
                    <Input placeholder='请输入姓名' />
                </Form.Item>
                <Form.Item
                    name='password'
                    label='密码'
                    rules={[{ required: true, message: '密码不能为空' }]}
                >
                    <Input type='password' clearable placeholder='请输入密码' />
                </Form.Item>
            </Form>
        </div>
    );
}

export default Index;
